package com.sylar.lelepub.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.sylar.lelepub.R;

public class OrderAdapter extends BaseAdapter {
	// private List<DetailPage> detailPages;
	private Context mContext;
	private LayoutInflater mInflater;
	private List<String> detailPages;

	public OrderAdapter(Context context) {
		mContext = context;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public void setListPageItems(List<String> detailPages) {
		this.detailPages = detailPages;
	}

	public int getCount() {
		if (detailPages != null)
			return detailPages.size();
		return 0;
	}

	// public DetailPage getItem(int position) {
	// if(detailPages!=null )
	// return detailPages.get(position);
	// return null;
	// }

	@Override
	public String getItem(int position) {
		if (detailPages != null)
			return detailPages.get(position);
		return null;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		ImageHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.order_list_item, null);
			holder = new ImageHolder();
			holder.tv_sleep_pub_bed_name = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_name);
			holder.tv_sleep_pub_bed_type = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_type);
			holder.tv_sleep_pub_bed_time = (TextView) convertView.findViewById(R.id.tv_sleep_pub_bed_time);
			holder.btn_sleep_pub_bed_confirm = (Button) convertView.findViewById(R.id.btn_sleep_pub_bed_confirm);
			convertView.setTag(holder);
		} else {
			holder = (ImageHolder) convertView.getTag();
		}

		if (position % 2 == 0) {
			holder.btn_sleep_pub_bed_confirm.setText("已确认");
		} else if (position % 2 == 1) {
			holder.btn_sleep_pub_bed_confirm.setText("确认中");
		} else if (position % 2 == 3) {
			holder.btn_sleep_pub_bed_confirm.setText("已入住");
		}

		return convertView;
	}

	private class ImageHolder {
		public TextView tv_sleep_pub_bed_name;
		public TextView tv_sleep_pub_bed_type;
		public TextView tv_sleep_pub_bed_time;
		public Button btn_sleep_pub_bed_confirm;
	}
}
